package DP.子序列;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;

import static MyUtils.MHUtils.*;
import static MyUtils.MHMoban.*;

/*
dp[i] 译时用resGan：包含当前i的最大递增子序列长度值

for i<n && 这里条件 只要1个不满足就retrun
还是里面if好
 */
public class 最长递增子序列300_DP {
    @Test
    public void test() {
//        int[] p = {0,1,0,3,2,3};
        int[] p = {10,9,2,5,3,7,101,18};
        System.out.println(lengthOfLIS(p));
    }

    public int lengthOfLIS(int[] nums) {
        int[] dp = new int[nums.length];
        dp[0]=1;
        for (int i = 1; i < nums.length; i++) {
            int max = -1;
            for (int l = 0; l <= i-1 ; l++) {
                if(nums[i]>nums[l]) {
                    max = Math.max(dp[l], max);
                }
            }
            //别忘+1本身 / 没有比当前i小的->设为1
            dp[i] = max==-1?
                    1:max+1;
        }
        //res不是[n-1],需要遍历拿到max
        int max = Integer.MIN_VALUE;
        for (int i = 0; i < dp.length; i++) {
            max = Math.max(dp[i],max);
        }
        return max;
    }
}
